package LC;

import java.util.HashMap;

/**
 * @ClassName JZ48
 * @Description: TODO
 * @Author hl
 * @Date 2020/9/27
 * @Version V1.0
 **/
public class JZ48 {
    public int lengthOfLongestSubstring(String s) {
        if(s==null) return 0;
        int ans=0;
        HashMap<Character,Integer> map=new HashMap<>();
        for(int i=0,j=0;i<s.length();i++){
            if(map.containsKey(s.charAt(i))){
                j=Math.max(j,map.get(s.charAt(i)));
            }
            ans=Math.max(ans,i-j+1);
            map.put(s.charAt(i),i+1);
        }
        return  ans;
    }
}
